import requests
from requests.utils import dict_from_cookiejar, cookiejar_from_dict, add_dict_to_cookiejar

url = 'https://www.wanandroid.com/user/login'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
payload = {
    'username': 'weixuesong',
    'password': 'wxs2011133069'
}
response = requests.post(url, data=payload, headers=headers)
# 打印Response对象
print(response)

# 获取json响应并转dict
print(response.json())

# 获取headers
print(response.request.headers)

# 获取cookies
cookies = response.cookies
print(cookies)

# CookieJar --> Dict
cookie_dict = cookies.get_dict()
print(cookie_dict)
cookie_dict = dict_from_cookiejar(cookies)
print(cookie_dict)

# Dict --> CookieJar
print(cookiejar_from_dict(cookie_dict))
print(add_dict_to_cookiejar(None, cookie_dict))
